package com.atguigu.guli.service.edu.service.impl;

import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.entity.query.TeacherQuery;
import com.atguigu.guli.service.edu.mapper.TeacherMapper;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2021-06-24
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    // 分页查询
    @Override
    public Page<Teacher> getPageByQuery(Page<Teacher> page, TeacherQuery query) {

        LambdaQueryWrapper<Teacher> querywrapper = new LambdaQueryWrapper<>();
        //接收传入的条件
        String name = query.getName();
        Integer level = query.getLevel();
        String joinDateBegin = query.getJoinDateBegin();
        String joinDateEnd = query.getJoinDateEnd();

        //判断条件
        if(!StringUtils.isEmpty(name)) {
            querywrapper.like(Teacher::getName, name);
        }
       if (level != null) {
           querywrapper.eq(Teacher::getLevel, level);
       }
       if (!StringUtils.isEmpty(joinDateBegin)) {
           querywrapper.ge(Teacher::getJoinDate, joinDateBegin);
       }
       if (!StringUtils.isEmpty(joinDateEnd)) {
           querywrapper.le(Teacher::getJoinDate, joinDateEnd);
       }

        //System.out.println("query: " + query);
        return this.page(page, querywrapper);
    }
}
